package cc.fine.svc.main.controller.rel;


import cc.fine.svc.common.utils.R;
import cc.fine.svc.main.bean.FineMessage;
import cc.fine.svc.main.bean.po.RelUserVideoFavor;
import cc.fine.svc.main.service.rel.RelUserVideoFavorService;
import cc.fine.svc.main.utils.MqUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyihe
 * @since 2023-10-25
 */
@RestController
@RequestMapping("/favor")
@Api(description = "给视频点赞")
public class RelUserVideoFavorController {

    @Autowired
    private RelUserVideoFavorService favorService;

    @Autowired
    private MqUtils mqUtils;

    @ApiOperation("给视频点赞")
    @PostMapping("/{userId}/{videoId}")
    public R favor(@PathVariable("userId") String userId,
                   @PathVariable("videoId") String videoId) {

        RelUserVideoFavor favor = new RelUserVideoFavor();
        favor.setUserId(userId);
        favor.setVideoId(videoId);

        /**
         * 调用异步任务来给视频点赞
         */
        FineMessage message = new FineMessage(FineMessage.FAVOR, favor);
        mqUtils.send(message);


        return R.ok();
    }

    @ApiOperation("取消视频的点赞")
    @DeleteMapping("/{userId}/{videoId}")
    public R disFavor(@PathVariable String userId,
                      @PathVariable String videoId) {
        RelUserVideoFavor favor = new RelUserVideoFavor();
        favor.setUserId(userId);
        favor.setVideoId(videoId);

        mqUtils.send(new FineMessage(FineMessage.DIS_FAVOR, favor));

        return R.ok();
    }

}

